package com.draem0507.refactor;

import java.util.Random;
import java.util.regex.Pattern;

/**
 * @title what to do .
 * @desc
 * @atuh lwx
 * @createtime on 2015/12/9 18:34
 */
public class RefactorDemo {


    public static void main(String[] args) {



        testDemo1();


    }



    public static void testDemo1(){


        StringCalculator1 stringCalculator1=new StringCalculator1();


        stringCalculator1.calculate("1+2 ");
    }



}

class StringCalculator1{


    public  void calculate(String expression){

        int firstNum= new Random().nextInt(5);
        int secondNum= new Random().nextInt(5);
        boolean legalExpress=new Random().nextBoolean();
        Pattern pattern = Pattern.compile("/\\d+\\s?+([^\\w\\d\\s])/");
        legalExpress  =pattern.matcher(expression).find();
        if(legalExpress){

            System.out.println( firstNum+secondNum);
        }


    }



}
class StringCalculator2{


    public  void calculate(String expression){

        int firstNum= new Random().nextInt(5);
        int secondNum= new Random().nextInt(5);
        boolean legalExpress=checkExpress(expression);
        if(legalExpress){

            System.out.println( firstNum+secondNum);
        }


    }

    private boolean checkExpress(String expression ){

        boolean legalExpress=new Random().nextBoolean();
        Pattern pattern = Pattern.compile("/\\d+\\s?+([^\\w\\d\\s])/");
        legalExpress  =pattern.matcher(expression).find();
        return legalExpress;
    }



}
